-
Notifications
You must be signed in to change notification settings - Fork 252
Add support for non-standard content/images scales #166
base: master
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
I'd like to write two tests for the same screen where there's both the 2x and 3x device scale cases. Is the pull request required for that? |
@lyahdav I think this is what you're looking for. The idea here is that the developer can indeed define views with different content scale factors or layers with different contents scales that are needed by the same instance of the app, and test them on any simulator/device regardless of what that device's main screen's scale is. So inside a FBSnapshotTestCase you could write something like:
The two tests will go look for reference images called respectively |
Hello @djrtl I have a very simple test: func testProfile() {
let customSizeFrame = ...
let myView = ...
view.frame = customSizeFrame
manualScale = 2
FBSnapshotVerifyView(view)
} However, when I run it in a @2x scale device with reference imagefailed imagediffIt seems like it is applying a wrong scale to the reference image when comparing both. Any idea how to fix this? Thank you! |
Hello @victorBaro, I made this quite some time ago and I thought I had tested that situation, but then again maybe not. I'm sorry for that. Right now it will be hard for me to look into this issue, I'll try to find the time in a few days. In the meantime if you want to look into it yourself, you might want to take a look at where the comparisons between the pixel resolutions of the reference and new snapshot are made to try and understand why they fail in that use case, as my guess is that that is what is happening. |
* Manual scale wasn't propagated properly to image capture and reference image selection methods
Hello @victorBaro, I think my colleague might have fixed the issue you reported. Could you please let us know if the version that includes his changes works correctly for you? |
Currently the framework uses [[UIScreen mainScreen] scale] for saving and comparing snapshots of views and layers.
If the view or layer are meant to be displayed at a different scale that doesn't match the main screen's one, the screenshots get resized (minified / magnified) and the comparisons are not correct any more from the point of view of the user, since the images are different from what will be shown to the user.
This PR tries to remove this limitation for those special cases by allowing the test developer to manually override the scale that will be used.